//
//  Config.h
//  TestProject
//
//  Created by 杨小平 on 14-8-18.
//  Copyright (c) 2014年 yangxiaoping. All rights reserved.
//

#ifndef TestProject_Config_h
#define TestProject_Config_h

//获得RGB颜色
#define kColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

/*根据label内容来调整label的高度*/
#define RESIZELABELBYCONTENT(_LABEL) ({\
CGSize maxSize = CGSizeMake(_LABEL.frame.size.width, 999);\
_LABEL.numberOfLines = 0;\
NSString *contentStr = _LABEL.text;\
UIFont *contentFont = _LABEL.font;\
CGRect contentFrame;\
NSString *version = [[UIDevice currentDevice] systemVersion];\
if ([version floatValue] < 7.0) {\
    CGSize contentStringSize = [contentStr sizeWithFont:contentFont constrainedToSize:maxSize lineBreakMode:_LABEL.lineBreakMode];\
    contentFrame = CGRectMake(5, 5, contentStringSize.width,contentStringSize.height);\
} else {\
    NSDictionary *contentDic = [NSDictionary dictionaryWithObjectsAndKeys:contentFont, NSFontAttributeName, nil];\
    CGSize contentStrSize = [contentStr boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:\contentDic  context:nil].size;\
    contentFrame = CGRectMake(5, 5, contentStrSize.width,contentStrSize.height);\
}\
_LABEL.frame = contentFrame;\
})\

//A better version of NSLog
#define NSLog(format, ...) do {      \
fprintf(stderr, "<%s : %d> %s\n",                                           \
[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String],  \
__LINE__, __func__);                                                        \
(NSLog)((format), ##__VA_ARGS__);                                           \
fprintf(stderr, "-------------------------------完美分割线---嘿嘿----------------------------\n");          \
} while (0)

//在全局配置文件(config.h)中定义了一个宏
#define SET_NAV_TITLE(_TITLE) ({\
UILabel *titleLabel = [[UILabel alloc] init];\
titleLabel.backgroundColor  = [UIColor clearColor];\
titleLabel.textColor        = [UIColor redColor];\
titleLabel.text             = _TITLE;\
titleLabel.font=[UIFont fontWithName:nil size:17.0f];\
[titleLabel sizeToFit];\
self.navigationItem.titleView = titleLabel;\
})

#endif
